const config = require('../config')
const sha1 = require('sha1')
let http = require('http'), url = require('url'), fs = require('fs');
module.exports = (app) => {
  app.get('/', (req, res) => {
    console.log((req.query))
    let token = config.wechat.token;
    let signature = req.query.signature;
    let nonce = req.query.nonce;
    let timestamp = req.query.timestamp;
    let echostr = req.query.echostr;
    let str = [token,timestamp,nonce].sort().join(''); //按字典排序，拼接字符串
    let sha = sha1(str); //加密
    let body  = (sha === signature)? echostr + '' : 'failed'; //比较并返回结果
    res.send(body);
  })

  app.use('/api/devicepower', require('./devicepower.js'));
  app.use('/api/speedtest', require('./speedtest.js'));

  //not used so far
  app.use('/api', require('./api-server'));
  app.use('/api/user', require('./users')); // 在所有users路由前加/api
}
